package com.coolwen.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * Created by user on 2016/7/9.
 */
public class CharacterFilter implements Filter {

    private String encoding;


    @Override
    public void init(FilterConfig cfg) throws ServletException {
        encoding = cfg.getInitParameter("encoding");
        if (encoding == null || "".equals(encoding.trim())) {
            encoding = "UTF-8";
        }

    }


    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        req.setCharacterEncoding(encoding);
        chain.doFilter(req, resp);
    }


    @Override
    public void destroy() {

    }
}
